| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 32 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 0 | 
| 1 | 'use strict';  | 
            ||
| 3 | define(function () { | 
            ||
| 4 | var self = this;  | 
            ||
| 5 | |||
| 6 |   self.distance = function distance(a, b) { | 
            ||
| 7 | return Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2);  | 
            ||
| 8 | };  | 
            ||
| 9 | |||
| 10 |   self.distancePoint = function distancePoint(a, b) { | 
            ||
| 11 | return Math.sqrt(distance(a, b));  | 
            ||
| 12 | };  | 
            ||
| 13 | |||
| 14 |   self.distanceLink = function distanceLink(p, a, b) { | 
            ||
| 15 | /* http://stackoverflow.com/questions/849211 */  | 
            ||
| 16 | var l2 = distance(a, b);  | 
            ||
| 17 |     if (l2 === 0) { | 
            ||
| 18 | return distance(p, a);  | 
            ||
| 19 | }  | 
            ||
| 20 | var t = ((p.x - a.x) * (b.x - a.x) + (p.y - a.y) * (b.y - a.y)) / l2;  | 
            ||
| 21 |     if (t < 0) { | 
            ||
| 22 | return distance(p, a);  | 
            ||
| 23 | }  | 
            ||
| 24 |     if (t > 1) { | 
            ||
| 25 | return distance(p, b);  | 
            ||
| 26 | }  | 
            ||
| 27 |     return distancePoint(p, { | 
            ||
| 28 | x: a.x + t * (b.x - a.x),  | 
            ||
| 29 | y: a.y + t * (b.y - a.y)  | 
            ||
| 30 | });  | 
            ||
| 31 | };  | 
            ||
| 32 | |||
| 33 | return self;  | 
            ||
| 34 | });  | 
            ||
| 35 |